<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%String path = request.getContextPath();%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<script type="text/javascript" language="javascript" src="<%=path %>/mnHtml/js/jquery-1.7.1.min.js"></script>
<script type="text/javascript" language="javascript" src="<%=path %>/mnHtml/js/examglobal.js"></script>
<title>市外模拟考信息查询</title>
</head>
<style type="text/css">
      body{
        text-align: center;
      }
      table{
        border-collapse: collapse;
        width: 60%;
      }
      table tr td
      {
         border-bottom: solid 1px #3399CC;
         border-left: solid 1px #3399CC;
         border-right: solid 1px #3399CC;
         border-top: solid 1px #3399CC;
         line-height: 25px;
         font-size: 12px;
      }
      #top{
        padding-top: 10px;
        text-align: center;
      }
      #title{
        background-color: #3399CC;
      }
    </style>
<body>
	<%
		if(session.getAttribute("user")==null){
			request.getRequestDispatcher("./login.jsp").forward(request, response);;
		}
	%>
	<br/><br/><br/><br/><br/><br/>

	<a href="${pageContext.request.contextPath }/DownloadServlet" style="color: red;"><strong>点击下载市外模拟考信息数据</strong></a>
	
	
	<br/><br/><br/><br/>
	<div id="divcnm"></div>
	
	
	<br/><br/><br/><br/>
	<table id="kaoshi" align="center">
		
	</table>
	<br/><br/><br/><br/><br/><br/><br/><br/>
	
</body>
<script type="text/javascript">
	$(function(){
		changci();
		checkIssky();
		
		//结束
		$(".isend").live("click",function(){
			var id = $(this).parent().parent().find(":first-child").html();
			update(id,"(已结束)");
			changci();
		});
		
		$(".open").live("click",function(){
			var id = $(this).parent().parent().find(":first-child").html();
			update(id,"");
			changci();
		});
		
		$(".notopen").live("click",function(){
			var id = $(this).parent().parent().find(":first-child").html();
			update(id,"(暂未开放)");
			changci();
		});
		
		$(".cnmclose").live("click",function(){
			updatecnm("否");
		});
		
		$(".cnmopen").live("click",function(){
			updatecnm("是");
		});
		
	});

		function changci(){
			$("#kaoshi").html("");
			$.ajax({
				type:'POST',
				async:false,
				url:PATH + '/ExamServlet?action=allExamnum',
				success:function(data){
					var ar = eval('(' + data + ')');
					var html = "";
					$.each(ar,function(x){
							var str = "";
							if(ar[x].flag==""){
								str = "<a href='javascript:void(0);' class='isend'>结束</a>&nbsp;&nbsp;&nbsp;<a href='javascript:void(0);' class='notopen'>暂不开放</a>";
							}else if(ar[x].flag=="(已结束)"){
								str = "<a href='javascript:void(0);' class='open'>开放</a>&nbsp;&nbsp;&nbsp;<a href='javascript:void(0);' class='notopen'>暂不开放</a>";
							}
							else if(ar[x].flag=="(暂未开放)"){
							str = "<a href='javascript:void(0);' class='open'>开放</a>&nbsp;&nbsp;&nbsp;<a href='javascript:void(0);' class='isend'>结束</a>";
							}
							
							if(ar[x].flag==""){
								ar[x].flag="(开放)";
							}
							
							html += "<tr><td>"+ar[x].id+"</td><td>"+ar[x].changci+"</td><td>"+ar[x].flag+"</td><td>"+str+"</td></tr>";
					});
					
					$("#kaoshi").append("<tr><td colspan='10'>市外模拟考试--场次信息操作(请慎操作)</td></tr>"+
							"<tr><td>编号</td><td>考试场次</td><td>状态</td><td>操作</td><tr/>"+html);
				}
			});
		}
		
		//修改
		function update(id,flag){
			$.ajax({
				type:"POST",
				async:false,
				url:PATH + "/ExamServlet?action=updateExamnum&id="+id+"&flag="+encodeURI(flag),
				success:function(data){
					alert(data);
				}
			});
		}
		
		function updatecnm(value){
			$.ajax({
				type:"POST",
				async:false,
				url:PATH + "/ExamServlet?action=updatecnm&value="+encodeURI(value),
				success:function(data){
					checkIssky();
					alert(data);
				}
			});		
		}
		
		
		function checkIssky(){
			$("#divcnm").html("");
			$.ajax({
				type:"post",
				async:false,
				url:PATH + "/ExamServlet?action=checkIssky",
				success:function(data){
					if(data=="是"){
						$("#divcnm").append("<font style='color: red;'><strong>是否开启校验（蓝天在读）：是</strong></font>&nbsp;&nbsp;&nbsp;<a href='javascript:void(0);' class='cnmclose'>关闭</a>");
					}else{
						$("#divcnm").append("<font style='color: red;'><strong>是否开启校验（蓝天在读）：否</strong></font>&nbsp;&nbsp;&nbsp;<a href='javascript:void(0);' class='cnmopen'>开启</a>");
					}
				}
			});
		}
		

		
</script>
</html>